/* 封装和文章相关的请求 */
import axios from '@/utils/request'
export function reqArticles (params = {}) {
  return axios({
    method: 'get',
    url: '/mp/v1_0/articles',
    params: params
  })
}

export function reqChannels () {
  return axios({
    method: 'GET',
    url: '/mp/v1_0/channels'
  })
}

// 后台接口风格：正常  /user/delete?id=1
// rest风格 delete /user/1
// json-server  get /user/1  delete /user/1  put /user/1
export function delArticle (id) {
  return axios({
    method: 'delete',
    url: `/mp/v1_0/articles/${id}`
  })
}

export function addArticle (isDraft, data) {
  return axios({
    method: 'POST',
    url: '/mp/v1_0/articles',
    params: {
      draft: isDraft
    },
    data
  })
}

// 根据id获取文章的详细信息
export function reqArticleDetail (id) {
  return axios({
    method: 'get',
    url: '/mp/v1_0/articles/' + id
  })
}
// 修改文章
export function editArticle (id, isDraft, data) {
  return axios({
    method: 'PUT',
    url: '/mp/v1_0/articles/' + id,
    params: {
      draft: isDraft
    },
    data
  })
}
// 修改评论状态
export function updateComment (id, status) {
  return axios({
    method: 'PUT',
    url: '/mp/v1_0/comments/status',
    params: {
      article_id: id
    },
    data: {
      allow_comment: status
    }
  })
}
